﻿/**
* Class:  
* Version: alpha
* Author:  Pavel Jacko
* Date:   18/05/2009
* Description:
* 
*/
package syerit.core.display
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;

	public class ImageMap extends Sprite
	{
		private var $url:String;
		private var $trigger:Function;
		private var $link:String;

		public function ImageMap (_x:Number,_y:Number,_w:Number,_h:Number,_link:String = "", _trigger:Function = null)
		{
			$trigger = _trigger;
			$link = _link;
			$url = _link;
			var $im:SolidShape = new SolidShape(_w,_h,0x000000);
			$im.alpha=0;
			addChild ($im);
			this.buttonMode = true;
			if (_link =="" && _trigger == null)
			{
				trace('deadlink');
			}
			else{
				this.addEventListener (MouseEvent.CLICK,clickHandler);
			}
			this.x=_x;
			this.y=_y;
		}
		private function clickHandler (_e:MouseEvent):void
		{
			if ($trigger != null)
			{
				$trigger.call ();
			}
			if ($link != ""){
				trace('navigating');
			navigateToURL (new URLRequest($url),"_self");
			}
		}
	}
}